/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Entity.Report;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Duc
 */
public class ReportTableModel extends AbstractTableModel{
    List<Report> listReport;
    ResourceBundle messages;
    public ReportTableModel(List<Report> listReport,ResourceBundle messages) {
        this.listReport = listReport;
        this.messages = messages;
    }
    public ReportTableModel(ResourceBundle messages) {
        this.messages = messages;
        this.listReport = new ArrayList<Report>();
    }
    public Report get(int index){
        return listReport.get(index);
    }
    @Override
    public int getRowCount() {
        return listReport.size();
    }

    @Override
    public int getColumnCount() {
       return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Report report = listReport.get(rowIndex);
         Timestamp timestamp = new Timestamp(report.getDatetime().getTime());
        String date =timestamp.toString();
        String status ="";
        if(report.getStatus()==0) status = "Unread";
        else status = "Read";
        switch(columnIndex){
            case 0: return rowIndex +1;
            case 1: return report.getSenderAccount();
            case 2: return date;
            case 3: return status;
            default: return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch(column){
            case 0: return messages.getString("order");
            case 1: return messages.getString("sender");
            case 2: return messages.getString("date");
            case 3: return messages.getString("status");
            default: return null;
        }
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch(columnIndex){
            case 0: return Integer.class;
            case 1: return String.class;
            case 2: return String.class;
            case 3: return String.class;
            default: return null;
        }
    }

    @Override
    public void fireTableDataChanged() {
        super.fireTableDataChanged();
    }
    
}
